<?php

namespace app\common\model\repair;

use app\common\model\BaseModel;

class RepairCateModel extends BaseModel
{
    protected $autoWriteTimestamp = true;
    protected $createTime = 'add_time';
    protected $updateTime = false;

    public static function tablePk(): string
    {
        return 'id';
    }

    public static function tableName(): string
    {
        return 'repair_cate';
    }


    public function getFullCateNameAttr()
    {
        $cateInfo = self::where('id', $this->id)->find();
        if ($cateInfo) {
            $path = trim($this->path, '/');
            $path = str_replace('/', ',', $path) . ',' . $this->id;
            $regionNames = self::whereIn('id', $path)->select()->toArray();
            $cateNames = [];
            foreach ($regionNames as $key => $value) {
                $cateNames[] = $value['cate_name'];
            }
            return implode(' / ', $cateNames);
        }
        return '';
    }
}
